local skel = fk.CreateSkill {
  name = "emo__yuanji",
  tags = {Skill.Compulsory},
}

local on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3)
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, skel.name, nil, true, player)
    cards = table.filter(cards, function (id) return room:getCardArea(id) == Card.Processing end)
    local get = {}
    for _, id in ipairs(cards) do
      local c = Fk:getCardById(id)
      if not c.is_damage_card then
        room:setCardEmotion(id, "judgegood")
        table.insert(get, id)
      end
    end
    room:delay(700)
    if #get > 0 then
      if player:isAlive() then
        room:obtainCard(player, get, true, fk.ReasonJustMove, player, skel.name)
      else
        room:cleanProcessingArea(get, skel.name)
      end
    end
    cards = table.filter(cards, function (id) return room:getCardArea(id) == Card.Processing end)
    if #cards > 0 then
      room:moveCards{
        ids = cards,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonJustMove,
        moveVisible = false,
        skillName = skel.name,
        drawPilePosition = -1,
      }
    end
  end

skel:addEffect(fk.Damage, {
  anim_type = "offensive",
  on_use = on_use
})

skel:addEffect(fk.Damaged, {
  anim_type = "offensive",
  on_use = on_use
})

Fk:loadTranslationTable{
  ["emo__yuanji"] = "怨积",
  [":emo__yuanji"] = "锁定技，当你造成或受到伤害后，你亮出牌堆顶的三张牌并获得非伤害类牌，剩余牌置于牌堆底。",

  ["$emo__yuanji1"] = "下民无知，奉予不恭，合当孥戮。",
  ["$emo__yuanji2"] = "时日曷丧？哈哈，咸拟一万年！",
}


return skel
